package com.wonyesoft.wuliu.acticity;

import java.io.File;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.util.PreferencesCookieStore;
import com.wonyesoft.wuliu.AppContent;
import com.wonyesoft.wuliu.R;
import com.wonyesoft.wuliu.acticity.base.BaseActivity;
import com.wonyesoft.wuliu.acticity.utils.FileUtils;
import com.wonyesoft.wuliu.acticity.utils.PhotoUtils;
import com.wonyesoft.wuliu.acticity.utils.StringUtils;
import com.wonyesoft.wuliu.acticity.utils.ToastUtils;
import com.wonyesoft.wuliu.api.GagApi;
import com.wonyesoft.wuliu.model.CarType;
import com.wonyesoft.wuliu.model.CargoInfo;
import com.wonyesoft.wuliu.vo.JsonRequest;
import com.wonyesoft.wuliu.vo.JsonResponse;
import com.wonyesoft.wuliu.vo.State;


public class OrderDetails extends BaseActivity implements OnClickListener {

	private TabHost mTabHost;
	private RadioGroup mRadioGroup;
	private RelativeLayout a11_common,a30_common;
	private TextView title, head_right, a0_common, a12_common,myorder_xiangxi_shrphone;
	private ImageView head_left,driver_imgone;
	private ListView mylist;
	private SimpleAdapter adapter;
	private List<Map<String, Object>> list;
	private Button a2_common, a1_common;
	private TextView myorder_xiangxi_order, myorder_xiangxi_money,
			myorder_xiangxi_origin, myorder_xiangxi_zhongdian,
			myorder_xiangxi_time, myorder_xiangxi_payment,
			myorder_xiangxi_goods, myorder_xiangxi_phone,
			myorder_xiangxi_status,myorder_xiangxi_moneytext,jy;
	private Gson gson = new Gson();
	private HttpUtils http = new HttpUtils();
	private RequestParams params;
	private AppContent app;
	private PreferencesCookieStore preferencesCookieStore;
	private List<CargoInfo> sourceDateList;
	private List<CarType> sourceCarTypeList;
	private String orderListId;
	private int a1_mark = 1;
	private int a2_mark = 1;
	private RelativeLayout a9_common;
	private String intPrice;
	//订单ID，用来更新订单
	private String cargoId;
	private final String[] arraycargopaytype = new String[] { "线下支付", "在线支付" };

	private final String[] arraycargoisback = new String[] { "有回单", "没有回单" };

	private final String[] arraycargochargetype = new String[] { "到付", "预付" };

	private final String[] arraycargotype = new String[] { "一般","易碎", "易燃", "易爆"
			 };
	private final String[] arraycargoweight = new String[] { "1吨以下", "3吨以内",
			"5吨以内", "5吨以上" };
	private final String[] arraycargovolme = new String[] { "1立方米以内", "3立方米以内",
			"5立方米以内", "5立方米以上" };
	private final String[] arraycargocartype = new String[] { "小箱车(面包,金杯)","0.5T车", "1T车",
			"2T车", "4T车", "5T车", "8T车" };
	private Bundle bundle2;
	private String[] noticeMsg = new String[] { "无", "无", "无" };
	private final String[] arraycargocarnotice = null;

	private int carTypeIds[] = { 1, 2, 3 ,4,5,6,7};
	
	private int ownCarTypeId = 0;
	

	// 相册的RequestCode
	public static final int INTENT_REQUEST_CODE_ALBUM = 0;
	// 照相的RequestCode
	public static final int INTENT_REQUEST_CODE_CAMERA = 1;
	// 裁剪照片的RequestCode
	public static final int INTENT_REQUEST_CODE_CROP = 2;
	// 滤镜图片的RequestCode
	public static final int INTENT_REQUEST_CODE_FLITER = 3;
	
	private Bitmap mUserPhoto;
	
	private String mTakePicturePath;
	private EditText c;

	// 图片在SD卡中的缓存路径
	private static final String IMAGE_PATH = Environment
			.getExternalStorageDirectory().toString()
			+ File.separator
			+ "tczh"
			+ File.separator + "Images" + File.separator;

	@SuppressLint("NewApi")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_myorder_conent_xiang);
		Bundle bundle = getIntent().getExtras();
		orderListId = bundle.getString("listid");
		System.out.println("orderListId:" + orderListId);
		preferencesCookieStore = app.getPreferencesCookieStore();
		bundle2 = new Bundle();
		initIds();
		if (null != orderListId && !(orderListId.isEmpty())) {
			System.out.println("没进来？");
			getPlanDetails();
		}

	}

	private void initIds() {
		
		jy = (TextView) findViewById(R.id.jy);
		jy.setOnClickListener(this);
		a30_common = (RelativeLayout) findViewById(R.id.a30_common);
		a30_common.setOnClickListener(this);
		myorder_xiangxi_shrphone = (TextView) findViewById(R.id.myorder_xiangxi_shrphone);
		myorder_xiangxi_moneytext = (TextView) findViewById(R.id.myorder_xiangxi_moneytext);
		myorder_xiangxi_order = (TextView) findViewById(R.id.myorder_xiangxi_order);
		myorder_xiangxi_money = (TextView) findViewById(R.id.myorder_xiangxi_money);
		myorder_xiangxi_origin = (TextView) findViewById(R.id.myorder_xiangxi_origin);
		myorder_xiangxi_zhongdian = (TextView) findViewById(R.id.myorder_xiangxi_zhongdian);
		myorder_xiangxi_time = (TextView) findViewById(R.id.myorder_xiangxi_time);
		myorder_xiangxi_payment = (TextView) findViewById(R.id.myorder_xiangxi_payment);
		//myorder_xiangxi_goods = (TextView) findViewById(R.id.myorder_xiangxi_goods);
		myorder_xiangxi_phone = (TextView) findViewById(R.id.myorder_xiangxi_phone);
		myorder_xiangxi_status = (TextView) findViewById(R.id.myorder_xiangxi_status);
		a11_common = (RelativeLayout) findViewById(R.id.a11_common);
		a12_common = (TextView) findViewById(R.id.a12_common);
		a0_common = (TextView) findViewById(R.id.a0_common);
		a2_common = (Button) findViewById(R.id.a2_common);
		a1_common = (Button) findViewById(R.id.a1_common);
		a2_common.setOnClickListener(this);
		a1_common.setOnClickListener(this);
		title = (TextView) findViewById(R.id.head_title);
		head_left = (ImageView) findViewById(R.id.head_left);
		a9_common = (RelativeLayout) findViewById(R.id.a9_common);
		head_left.setVisibility(0);
		title.setText("订单详情");
		head_left.setOnClickListener(this);
		a11_common.setOnClickListener(this);
		driver_imgone = (ImageView) findViewById(R.id.driver_imgone);
		driver_imgone.setOnClickListener(this);

	}

	private void initViews() {
		// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
		// String crtime = "sdfasdfdsafds";
		// String crtime = sdf.format(sourceDateList.get(0).getCreateTime());
		if(Integer.valueOf(sourceDateList.get(0).getCarType())==0) a0_common
		.setText("未选择车辆类型");else
		if (!(StringUtils.isEmpty(sourceDateList.get(0).getCarType())))
			a0_common.setText(arraycargocartype[Integer.valueOf(sourceDateList
					.get(0).getCarType())-1]);
		a12_common.setText(sourceDateList.get(0).getCargoStatus() + "");
		myorder_xiangxi_time
				.setText(sourceDateList.get(0).getCreateTime() + "");
		myorder_xiangxi_order.setText(sourceDateList.get(0).getFlowId() + "");
		myorder_xiangxi_money.setText(sourceDateList.get(0).getTotalFee()
				+ "");
		myorder_xiangxi_shrphone.setText(sourceDateList.get(0).getSdMobile()
				+ "");
		myorder_xiangxi_origin.setText(sourceDateList.get(0).getReAddress());
		myorder_xiangxi_zhongdian.setText(sourceDateList.get(0).getSdAddress());
		if(Integer.valueOf(sourceDateList.get(0).getPayMent())==0) myorder_xiangxi_payment
		.setText("未选择支付方式");else
		myorder_xiangxi_payment
				.setText(arraycargochargetype[Integer.valueOf(sourceDateList.get(0).getPayMent())-1] + "");
		/*
		 * myorder_xiangxi_goods .setText(sourceDateList.get(0).getCargoType() +
		 * "");
		 */
		/*if (!(StringUtils.isEmpty(sourceDateList.get(0).getCargoType())))
			myorder_xiangxi_goods.setText(arraycargotype[Integer
					.valueOf(sourceDateList.get(0).getCargoType())]);*/
		//司机电话
		myorder_xiangxi_phone.setText(sourceDateList.get(0).getDriverMobile());
		myorder_xiangxi_status.setText(sourceDateList.get(0).getPayType());
		// switch (sourceDateList.get(0).getFlowStatus()) {
		System.out.println("flowStatus:"+ Integer.valueOf(sourceDateList.get(0).getFlowStatus()));
		switch (Integer.valueOf(sourceDateList.get(0).getFlowStatus())) {
		case 2:
			a1_common.setText("确认订单");
			a2_common.setText("议价");
			a1_common.setClickable(true);
			//bundle2.putString("flowId", sourceDateList.get(0).getFlowId() + "");
			a1_mark = 1;
			a2_mark = 1;
			break;
		case 1:
			a1_mark = 2;
			a2_mark = 2;
			a1_common.setText("等待司机修改");
			a2_common.setText("刷新");
			a1_common.setBackgroundColor(getResources().getColor(R.color.base_colorC));
			a1_common.setClickable(false);
			break;
		case 3:
			a1_mark = 3;
			a2_mark = 2;
			a1_common.setText("订单派送中");
			a2_common.setText("刷新");
			a1_common.setBackgroundColor(getResources().getColor(
					R.color.base_colorC));
			a1_common.setClickable(false);
			break;
		case 4:
			//a1_mark = 2;
			//a2_mark = 2;
			a1_common.setText("已完成");
			a2_common.setText("评价");
			a2_mark = 5;
			a1_common.setBackgroundColor(getResources().getColor(
					R.color.base_colorC));
			a1_common.setClickable(false);
			break;
		default:
			break;
		}

	}

	private void changeMoney() {
		{	 c = new EditText(OrderDetails.this);
		 c.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
		 c.setHint("请输入您的期望价格");
		 new AlertDialog.Builder(this).setTitle("请输入您的意向金额").setPositiveButton("确定", new DialogInterface.OnClickListener() {
			
			

			public void onClick(DialogInterface dialog, int which) {
				if((!StringUtils.isEmpty(c.getText().toString()))&&Double.valueOf(c.getText().toString())>0) {intPrice = c.getText().toString();
				
				a1_common.setText("提交议价");
				a1_common.setClickable(true);
				myorder_xiangxi_moneytext.setText("期望价格 : ");
				myorder_xiangxi_money.setText(intPrice);
				a1_mark = 5;
				}else showLongToast("未正确输入金额！");
			}
		}).setNegativeButton("取消", null).setView(c).show();
		//changeList();
	}
		
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.jy:
			openActivity(ZiFeiActivity.class);
			break;
		case R.id.head_left:
			finish();
			break;
		case R.id.a11_common:
			Intent intent = new Intent();
			System.out.println("real电话");
			// 激活源代码,添加intent对象
			intent.setAction("android.intent.action.CALL");
			// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
			intent.setData(Uri.parse("tel:"
					+ myorder_xiangxi_phone.getText().toString()));
			// 激活Intent
			startActivity(intent);
			break;
		case R.id.myorder_xiangxi_phone:
			System.out.println("myorder_xiangxi_phonetext");

			if(StringUtils.isEmpty(myorder_xiangxi_phone.getText().toString()))
			{
				showLongToast("司机电话为空");
				break;
			}
			Intent intent2 = new Intent();
			// 激活源代码,添加intent对象
			intent2.setAction("android.intent.action.CALL");
			// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
			intent2.setData(Uri.parse("tel:"
					+ myorder_xiangxi_phone.getText().toString()));
			// 激活Intent
			startActivity(intent2);
			break;
		case R.id.a30_common:
			
			if(StringUtils.isEmpty(myorder_xiangxi_shrphone.getText().toString()))
			{
				showLongToast("收件人电话为空");
				break;
			}
			Intent intent9 = new Intent();
			System.out.println("real电话");
			// 激活源代码,添加intent对象
			intent9.setAction("android.intent.action.CALL");
			// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
			intent9.setData(Uri.parse("tel:"
					+ myorder_xiangxi_shrphone.getText().toString()));
			// 激活Intent
			startActivity(intent9);
			break;
		case R.id.a1_common:
			if (a1_mark == 1) {
				System.out.println("qrdd方法调用");
				qrdd();}else 
			if (a1_mark == 3) { //订单派送中
			a1_common.setBackgroundColor(getResources().getColor(
					R.color.base_colorC));
			a1_common.setClickable(false);}else if(a1_mark==5) yj();
			break;
		case R.id.a2_common:
			if (a2_mark == 1)
				changeMoney(); else
			if (a2_mark == 2)
				refreshList();
			break;
		case R.id.driver_imgone:
				updateImg();//上传凭证
			break;
		default:
			break;
		}
	}

	private void yj() {
		// 更新订单货物信息
		
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put("transPrice", intPrice);
			dataMap.put("totalFee", intPrice);
			dataMap.put("flowId", orderListId);
		    dataMap.put("cargoId", sourceDateList.get(0).getCargoId());
			JsonRequest jr = JsonRequest.getInit();
			jr.setData(dataMap);
			String json = gson.toJson(jr);
			params = new RequestParams();
			params.addBodyParameter("jsonParam", json);
			http.configCookieStore(preferencesCookieStore);
			http.send(HttpRequest.HttpMethod.POST, GagApi.USERCHANGELIST, params,
					new RequestCallBack<String>() {

						@Override
						public void onSuccess(ResponseInfo<String> responseInfo) {

							System.out.println("进入添加addcargo");
							Gson gson2 = new Gson();
							JsonResponse jrs = gson2.fromJson(responseInfo.result,
									JsonResponse.class);
							System.out.println(responseInfo.result);
							State state = jrs.getState();
							// System.out.println(preferencesCookieStore);
							if (state.getCode().equals(State.SUCEECCODE)) {
								showLongToast("议价已经提交，请等待司机确认！");
								getPlanDetails();
							} else
								// System.out.println(state.getMsg());
								showLongToast(state.getMsg());
						}

						@Override
						public void onFailure(HttpException error, String msg) {
							// testTextView.setText(error.getExceptionCode() + ":" +
							// msg);
							System.out.println(msg);
						}
					});
		
	}

	private void updateImg() {
		new AlertDialog.Builder(OrderDetails.this)
		.setTitle("上传凭证图片")
		.setItems(new String[] { "拍照上传", "上传手机中的照片" },
				new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog,
							int which) {
						Intent intent = null;
						switch (which) {
						case 0:

							FileUtils.createDirFile(IMAGE_PATH);
							intent = new Intent(
									MediaStore.ACTION_IMAGE_CAPTURE);
							String path = IMAGE_PATH
									+ UUID.randomUUID()
											.toString() + "jpg";
							File file = FileUtils
									.createNewFile(path);
							if (file != null) {
								intent.putExtra(
										MediaStore.EXTRA_OUTPUT,
										Uri.fromFile(file));
							}
							startActivityForResult(intent,
									INTENT_REQUEST_CODE_CAMERA);
							mTakePicturePath = path;
							break;

						case 1:

							Intent intent2 = new Intent(
									Intent.ACTION_PICK, null);
							intent2.setDataAndType(
									MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
									"image/*");
							startActivityForResult(intent2,
									INTENT_REQUEST_CODE_ALBUM);
							break;
						}
					}
				})
		.setNegativeButton("取消",
				new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog,
							int which) {
						dialog.cancel();
					}
				}).create().show();

	}

	private void changeList() {
		openActivity(AddCargoActivity.class, bundle2);
		finish();
	}

	private void refreshList() {
		getPlanDetails();
	}

	private void wcdd() {
		Bundle b = new Bundle();
		b.putString("flowID", sourceDateList.get(0).getFlowId() + "");
		// b.putString("", value);
		openActivity(AddCargoActivity.class, b);
	}

	private void ddxg() {

	}

	private void qrdd() {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		JsonRequest jr = JsonRequest.getInit();
		dataMap.put("flowId", orderListId);
		cargoId = sourceDateList.get(0).getCargoId();
		if(!StringUtils.isEmpty(orderListId)) dataMap.put("cargoId", cargoId);
		//dataMap.put("flowStatus",1 );
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(AppContent.getPreferencesCookieStore());
		http.send(HttpRequest.HttpMethod.POST, GagApi.USERCOMFIRM,
				params, new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("用户订单确认");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();

						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {
							// 存用户登录信息
							// System.out.println(responseInfo.result);
							showLongToast("确认订单完成,等待司机确认！");
							refreshList();
							
							// System.out.println(jrs.getParam("rows"));

						} else {
							ToastUtils.showLong(state.getMsg());
							if (state.getCode().equals(State.UNLOGIN)) {
								openActivity(UserLoginActivity.class);
								finish();
							}

						}
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						System.out.println(msg);
					}
				});
	}

	private void getPlanDetails() {
		showLoadingDialog("数据载入中 ...");
		Map<String, Object> dataMap = new HashMap<String, Object>();
		JsonRequest jr = JsonRequest.getInit();
		dataMap.put("flowId", orderListId);
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(preferencesCookieStore);
		http.send(HttpRequest.HttpMethod.POST, GagApi.GETSINGLEPLANLIST,
				params, new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						dismissLoadingDialog();
						System.out.println("进入订单详情");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();

						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {
							// 存用户登录信息
							// System.out.println(responseInfo.result);

							if (gson2 != null) {
								Type type = new TypeToken<List<CargoInfo>>() {
								}.getType();
								try {
									sourceDateList = gson2.fromJson(
											new JSONObject(responseInfo.result)
													.getJSONObject("data")
													.getJSONArray("rows")
													+ "", type);
								} catch (JsonSyntaxException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
								if (null != sourceDateList)
									initViews();
							}
							// System.out.println(jrs.getParam("rows"));

						} else {
							ToastUtils.showLong(state.getMsg());
							if (state.getCode().equals(State.UNLOGIN)) {
								openActivity(UserLoginActivity.class);
								finish();
							}

						}
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						dismissLoadingDialog();
						System.out.println(msg);
					}
				});

	}

	private void getCarType() {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		JsonRequest jr = JsonRequest.getInit();
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(preferencesCookieStore);
		http.send(HttpRequest.HttpMethod.POST, GagApi.GETCARPRICE, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入getcartype");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();
						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {

							if (gson2 != null) {
								Type type = new TypeToken<List<CarType>>() {
								}.getType();
								try {
									sourceCarTypeList = gson2.fromJson(
											new JSONObject(responseInfo.result)
													.getJSONObject("data")
													.getJSONArray("rows")
													+ "", type);
								} catch (JsonSyntaxException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
								if (null != sourceCarTypeList)
									initCarTypeList();

							} else
								System.out.println(state.getMsg());

						} else
							// System.out.println(state.getMsg());
							showLongToast(state.getMsg());
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						System.out.println(msg);
					}
				});
	}

	protected void initCarTypeList() {

		for (int i = 0; i < sourceCarTypeList.size(); i++) {

			arraycargocartype[i] = sourceCarTypeList.get(i).getCarType();
			noticeMsg[i] = sourceCarTypeList.get(i).getCarType()
					+ sourceCarTypeList.get(i).getDisPrice() + "/"
					+ sourceCarTypeList.get(i).getBaseDistance() + "公里，超过之后"
					+ sourceCarTypeList.get(i).getBaseDistance() + "/公里！";
			System.out.println(noticeMsg[i]);
		}

	}
	
	// 念念不忘，必有回响
		public void onActivityResult(int requestCode, int resultCode, Intent data) {
			super.onActivityResult(requestCode, resultCode, data);
			System.out.println("requestCode:" + requestCode);
			switch (requestCode) {

			case PhotoUtils.INTENT_REQUEST_CODE_ALBUM:
				System.out.println("0Photoutils进来了");
				if (data == null) {
					return;
				}
				if (resultCode == RESULT_OK) {
					if (data.getData() == null) {
						return;
					}
					if (!FileUtils.isSdcardExist()) {
						ToastUtils.showLong("SD卡不可用,请检查");
						return;
					}
					Uri uri = data.getData();
					String[] proj = { MediaStore.Images.Media.DATA };
					Cursor cursor = managedQuery(uri, proj, null, null, null);
					if (cursor != null) {
						int column_index = cursor
								.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
						if (cursor.getCount() > 0 && cursor.moveToFirst()) {
							String path = cursor.getString(column_index);
							Bitmap bitmap = BitmapFactory.decodeFile(path);
							if (PhotoUtils.bitmapIsLarge(bitmap)) {
								System.out.println("path");
								this.setUserPhoto(bitmap);

							} else {
								this.setUserPhoto(bitmap);
							}
						}
					}
				}
				break;

			case PhotoUtils.INTENT_REQUEST_CODE_CAMERA:
				if (resultCode == RESULT_OK) {
					System.out.println("Photoutils进来了");
					String path = this.getTakePicturePath();
					Bitmap bitmap = BitmapFactory.decodeFile(path);
					if (PhotoUtils.bitmapIsLarge(bitmap)) {
						System.out.println("path");
						this.setUserPhoto(bitmap);

					} else {
						this.setUserPhoto(bitmap);
					}
				}
				break;

			case PhotoUtils.INTENT_REQUEST_CODE_CROP:
				System.out.println("2Photoutils进来了");
				if (resultCode == RESULT_OK) {
					String path = data.getStringExtra("path");
					System.out.println(path);
					if (path != null) {
						Bitmap bitmap = BitmapFactory.decodeFile(path);
						driver_imgone.setImageBitmap(bitmap);
					}
				}
				break;
			}
		}

		//上传回单方法
		private void upHead(final String file, final Bitmap bitmap) {
			Map<String, Object> dataMap = new HashMap<String, Object>();
			JsonRequest jr = JsonRequest.getInit();
			jr.setData(dataMap);
			String json = gson.toJson(jr);
			params = new RequestParams();
			params.addHeader("enctype", "multipart/form-data");
			params.addBodyParameter("jsonParam", json);
			params.addBodyParameter("file", new File(file));
			// http.configCookieStore(App.getPreferencesCookieStore());
			http.send(HttpRequest.HttpMethod.POST, GagApi.ADDADDRESS, params,
					new RequestCallBack<String>() {

						public void onLoading(long total, long current,
								boolean isUploading) {
							if (isUploading) {
							} else {
							}
						}

						@Override
						public void onSuccess(ResponseInfo<String> responseInfo) {

							JsonResponse jrs = gson.fromJson(responseInfo.result,
									JsonResponse.class);
							State state = jrs.getState();
							// 存储userinfo信息
							if (state.getCode().equals(State.SUCEECCODE)) {
								if (bitmap != null) {
									
									setUserPhoto(bitmap);
								}
								showLongToast("上传成功");
							} else
								ToastUtils.showLong(state.getMsg());
						}

						@Override
						public void onFailure(HttpException error, String msg) {
							// testTextView.setText(error.getExceptionCode() + ":" +
							// msg);
						}
					});

		}

		public void setUserPhoto(Bitmap bitmap) {
			if (bitmap != null) {
				mUserPhoto = bitmap;
				System.out.println("setuserphoto");
				// mIvUserPhoto.setImageBitmap(mUserPhoto);
				return;
			}
			ToastUtils.showLong("未获取到图片");
			mUserPhoto = null;
			// mIvUserPhoto.setImageResource(R.drawable.ly_driver_tianjia);
		}

		public String getTakePicturePath() {
			return mTakePicturePath;
		}
		
	
}
